<?php

namespace app\common\model\jy;

class OrderRefund extends CUBase {
	protected $statusEnum = 'OrderRefundStatus';

	//店铺ID
	public function getSidAttr($value, $data) {
		$order = loadOnly('jy\\Order')->find('jy\\Order', $data['oid']);
		return $order ? $order['sid'] : '';
	}

	//退款操作日志
    public function getOrderRefundLogAttr($value, $data) {
    	return loadModel('jy\\OrderRefundLog')->append(['images_url'])->where(['orid' => $data['id']])->select();
    }

    //退款产品信息
    public function getOrderRefundProductAttr($value, $data) {
    	$model = loadModel('jy\\OrderRefundProduct')->alias('ORP');
        $model->join('order_product OP', 'ORP.opid = OP.id');
        $model->join('snapshot_product SP', 'OP.snapshotid = SP.id');
        $model->join('snapshot_product_specs SPS', 'OP.snapshotid = SPS.spid and OP.psid = SPS.psid');
        $model->field('ORP.id,ORP.num,ORP.createtime,ORP.updatetime,OP.pid,OP.num as buynum,SP.store_name,SP.store_photo,SP.photo,SP.name,SP.selling,SP.classify,SP.ost_sale,SPS.name as psname, SPS.price as price, SPS.price * OP.num as total');
        $model->where('orid', $data['id']);
        $list = $model->select();
    	return $list;
    }

    //退款产品快照信息
    public function getOrderRefundProductSnapshotAttr($value, $data) {
        $opids = loadModel('jy\\OrderRefundProduct')->where('orid', $data['id'])->column('opid');
        $model = loadModel('jy\\OrderProduct');
        $model->append('snapshot');
        $model->whereIn('id', $opids);
        return $model->select();
    }

    //订单快递单号
    public function getExpressNumberAttr($value, $data) {
        $row = loadModel('jy\\OrderRefundExpressNumber')->where('orid', $data['id'])->find();
        return $row ? $row['express_number'] : '';
    }
}
